import 'package:flutter/material.dart';

class Content extends StatefulWidget {
  @override
  State<Content> createState() => _ContentState();
}

class _ContentState extends State<Content> {
  List codeList = [
    {"id": '1', 'text': '37', 'state': false},
    {"id": '2', 'text': '38', 'state': false},
    {"id": '3', 'text': '39', 'state': false},
    {"id": '4', 'text': '40', 'state': false},
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(15),
      child: Wrap(
        children: codeList
            .map((item) => GestureDetector(
                  onTap: () {
                    setState(() {
                      for (Map i in codeList) {
                        if (i['id'] == item['id']) {
                          i['state'] = true;
                        } else {
                          i['state'] = false;
                        }
                      }
                    });
                  },
                  child: Container(
                    margin: EdgeInsets.only(right: 3),
                    alignment: Alignment.center,
                    width: 60,
                    height: 30,
                    color: item['state']
                        ? Colors.red
                        : Color.fromRGBO(242, 242, 242, 1),
                    child: Text(
                      '${item['text']}码',
                      style: TextStyle(
                        color: item['state'] ? Colors.white : Colors.black,
                      ),
                    ),
                  ),
                ))
            .toList(),
      ),
    );
  }
}
